﻿using System;
using System.Threading;
using System.Diagnostics;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ArchiveRecoveryProgram
{
    class PvzWatcher
    {
        static string processName = "PlantsVsZombies";


        public PvzWatcher()
        {
            while (true)
            {
                // 获取当前系统中所有进程
                Process[] processes = Process.GetProcesses();

                // 检查是否有名为PlantsVsZombies的进程
                Process foundProcess = Array.Find(processes, process => process.ProcessName == processName);

                // 如果找到进程，为其注册退出事件
                if (foundProcess != null)
                {
                    // is_running = true;
                    foundProcess.EnableRaisingEvents = true;
                    foundProcess.Exited += (sender, e) =>
                    {
                        // is_running = false;

                        // 执行预定操作
                        // PerformPostExitOperations();
                    };
                    break;
                }
                else
                    Console.WriteLine("The process is not running.");
                // 等待一段时间再次检查
                System.Threading.Thread.Sleep(1000);
            }
        }
    }
}
